"GraalVM Rules for Bazel"

module(
    name = "rules_graalvm",
    version = "0.11.0",
)

JAVA_VERSION = "21"

PYTHON_VERSION = "3.11"

NODE_VERSION = "20.5.0"

GRAALVM_VERSION = "21.0.1"

GRAALVM_DIST = "ce"

GRAALVM_SDK_VERSION = "23.1.1"


##
## Dependencies: API
##

bazel_dep(
    name = "platforms",
    version = "0.0.7",
)
bazel_dep(
    name = "bazel_features",
    version = "1.0.0",
)
bazel_dep(
    name = "rules_java",
    version = "6.4.0",
)
bazel_dep(
    name = "bazel_skylib",
    version = "1.5.0",
)
bazel_dep(
    name = "apple_support",
    version = "1.8.1",
    repo_name = "build_bazel_apple_support",
)

##
## Dependencies: Development
##

bazel_dep(
    name = "rules_license",
    version = "0.0.7",
    dev_dependency = True,
)
bazel_dep(
    name = "rules_cc",
    version = "0.0.9",
    dev_dependency = True,
)
bazel_dep(
    name = "rules_python",
    version = "0.25.0",
    dev_dependency = True,
)
bazel_dep(
    name = "rules_testing",
    version = "0.4.0",
    dev_dependency = True,
)
bazel_dep(
    name = "aspect_bazel_lib",
    version = "1.34.1",
    dev_dependency = True,
)
bazel_dep(
    name = "aspect_rules_js",
    version = "1.32.0",
    dev_dependency = True,
)
bazel_dep(
    name = "rules_nodejs",
    version = "6.0.1",
    dev_dependency = True,
)
bazel_dep(
    name = "protobuf",
    version = "21.7",
    dev_dependency = True,
    repo_name = "com_google_protobuf",
)
bazel_dep(
    name = "rules_go",
    version = "0.41.0",
    dev_dependency = True,
    repo_name = "io_bazel_rules_go",
)
bazel_dep(
    name = "gazelle",
    version = "0.32.0",
    dev_dependency = True,
    repo_name = "bazel_gazelle",
)
bazel_dep(
    name = "rules_jvm_external",
    version = "5.3",
    dev_dependency = True,
)
bazel_dep(
    name = "stardoc",
    version = "0.6.2",
    dev_dependency = True,
    repo_name = "io_bazel_stardoc",
)
bazel_dep(
    name = "bazel_skylib_gazelle_plugin",
    version = "1.4.2",
    dev_dependency = True,
)
bazel_dep(
    name = "contrib_rules_jvm",
    version = "0.18.0",
    dev_dependency = True,
)
bazel_dep(
    name = "apple_rules_lint",
    version = "0.3.2",
    dev_dependency = True,
)
bazel_dep(
    name = "buildifier_prebuilt",
    version = "6.3.3",
    dev_dependency = True,
)

################################################################################
# rules_jvm_external
################################################################################

MAVEN_ARTIFACTS = [
    "org.graalvm.nativeimage:svm:%s" % GRAALVM_SDK_VERSION,
    "org.graalvm.sdk:graal-sdk:%s" % GRAALVM_SDK_VERSION,
    "org.graalvm.polyglot:polyglot:%s" % GRAALVM_SDK_VERSION,
]

MAVEN_REPOSITORIES = [
    "https://maven.pkg.st",
    "https://maven.google.com",
    "https://repo1.maven.org/maven2",
]

maven = use_extension(
    "@rules_jvm_external//:extensions.bzl",
    "maven",
    dev_dependency = True,
)
maven.install(
    name = "maven_gvm",
    artifacts = MAVEN_ARTIFACTS,
    lock_file = "//:maven_install.json",
    repositories = MAVEN_REPOSITORIES,
)
use_repo(
    maven,
    "maven_gvm",
    "unpinned_maven_gvm",
)

################################################################################
# rules_graalvm
################################################################################

gvm = use_extension(
    ":extensions.bzl",
    "graalvm",
    dev_dependency = True,
)
gvm.graalvm(
    name = "graalvm",
    distribution = GRAALVM_DIST,
    java_version = JAVA_VERSION,
    version = GRAALVM_VERSION,
)
use_repo(
    gvm,
    "graalvm",
)
use_repo(
    gvm,
    "graalvm_toolchains",
)

register_toolchains(
    "@graalvm_toolchains//:toolchain",
    dev_dependency = True,
)

register_toolchains(
    "@graalvm_toolchains//:toolchain_gvm",
    dev_dependency = True,
)

register_toolchains(
    "@graalvm//:bootstrap_runtime_toolchain",
    dev_dependency = True,
)

################################################################################
# rules_js
################################################################################

node = use_extension(
    "@rules_nodejs//nodejs:extensions.bzl",
    "node",
    dev_dependency = True,
)
node.toolchain(node_version = NODE_VERSION)

npm = use_extension(
    "@aspect_rules_js//npm:extensions.bzl",
    "npm",
    dev_dependency = True,
)
npm.npm_translate_lock(
    name = "npm",
    pnpm_lock = "//:pnpm-lock.yaml",
    verify_node_modules_ignored = "//:.bazelignore",
)
use_repo(npm, "npm")
